/**
 * 
 */
package microcredit.gui.table.impl;

import java.awt.Color;

import javax.swing.ImageIcon;

import microcredit.gui.table.EnumBeanTableModel;
import microcredit.gui.util.FormatUtilities;
import microcredit.model.MemberStatusHistory;
import microcredit.model.MemberToTrainingType;
import microcredit.model.domain.TrainingStatus;

enum MemberToTrainingTypeColumns {
	COLUMN_NAME,
	COLUMN_STATUS ,
	COLUMN_NOTES ,
	COLUMN_DATE,
}

public final class MemberToTrainingTypeTableModel extends
		EnumBeanTableModel<MemberToTrainingType,  MemberToTrainingTypeColumns > {

	@Override
	protected String getName(MemberToTrainingTypeColumns column) {
		switch(column) {
		case COLUMN_NAME : return "Name";
		case COLUMN_STATUS : return "Status";
		case COLUMN_NOTES : return "Notes";
		case COLUMN_DATE : return "Date";
		}
		return null;
	}
	
	@Override
	protected Color getForeground(MemberToTrainingType o,
			MemberToTrainingTypeColumns column) {
		if (o.getStatus() != null) {
			if (o.getStatus() == TrainingStatus.P) {
				return Color.BLUE;
			} else if (o.getStatus() == TrainingStatus.M) {
				return Color.RED;
			}
		}
		return null;
	}
	
	@Override
	protected int getWidth(MemberToTrainingTypeColumns column) {
		switch(column) {
		case COLUMN_NAME : return 200;
		case COLUMN_STATUS : return 120;
		case COLUMN_NOTES : return 300;
		case COLUMN_DATE : return 120;
		}
		return -1;
	}
	
	@Override
	public ImageIcon getRowIcon() {
		return new ImageIcon(MemberStatusHistory.class
				.getResource("/microcredit/icons/x16/blackboard.png"));
	}
	
	@Override
	protected Object getValue(MemberToTrainingType bean,
			MemberToTrainingTypeColumns column) {
		switch(column) {
		case COLUMN_NAME : return bean.getTrainingType().getCumulatedName();
		case COLUMN_STATUS : return bean.getStatus() != null ? bean.getStatus().getDisplayName() : " - ";
		case COLUMN_NOTES : return bean.getNotes();
		case COLUMN_DATE : return FormatUtilities.formatDate(bean.getDate());
		}
		return null;
	}

}